<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript">
	$.canEdit = true;
</script>
<script type="text/javascript">
	$.canDelete = true;
</script>
<script type="text/javascript">
	$.canGrant = true;
</script>
<script type="text/javascript">
	$.canEditPwd = true;
</script>
<script type="text/javascript">
	var dataGrid2;
	$(function() {
		dataGrid2 = $('#dataGrid2')
				.datagrid(
						{
							url : '${pageContext.request.contextPath}/accountController/dataGrid?uid=${account.uid}',
							fit : true,
							fitColumns : true,
							border : false,
							pagination : true,
							singleSelect : true,
							idField : 'id',
							pageSize : 5,
							pageList : [ 5, 10, 15, 20, 30 ],
							sortName : 'name',
							sortOrder : 'asc',
							checkOnSelect : false,
							selectOnCheck : false,
							nowrap : false,
							frozenColumns : [ [ {
								field : 'id',
								title : 'id',
								width : 150,
							//hidden : true
							}, {
								field : 'name',
								title : '编号',
								width : 80,
								sortable : true
							} ] ],
							columns : [ [ {
								field : 'currencyStr',
								title : '币种',
								width : 50,
								sortable : true
							}, {
								field : 'typeStr',
								title : '类型',
								width : 50,
								sortable : true
							}, {
								field : 'type',
								title : '类型',
								width : 50,
								sortable : true,
								hidden : true
							}, {
								field : 'stime',
								title : '开户时间',
								width : 100,
								sortable : true
							}, {
								field : 'amount',
								title : '金额',
								width : 150,
								sortable : true
							} ] ],
							toolbar : '#toolbar',
							onLoadSuccess : function() {
								$('#searchForm table').show();
								parent.$.messager.progress('close');

								$(this).datagrid('tooltip');
							},
							onRowContextMenu : function(e, rowIndex, rowData) {
								e.preventDefault();
								$(this).datagrid('unselectAll').datagrid(
										'uncheckAll');
								$(this).datagrid('selectRow', rowIndex);
								$('#menu').menu('show', {
									left : e.pageX,
									top : e.pageY
								});
							}
						});
	});

	function deleteFun(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = dataGrid2.datagrid('getSelections');
			id = rows[0].id;
		}
		dataGrid2.datagrid('unselectAll').datagrid('uncheckAll');

		parent.$.messager
				.confirm(
						'询问',
						'您是否要删除当前用户？',
						function(b) {
							if (b) {
								var currentUserId = '${sessionInfo.id}';/*当前登录用户的ID*/
								if (currentUserId != id) {
									parent.$.messager.progress({
										title : '提示',
										text : '数据处理中，请稍后....'
									});
									$
											.post(
													'${pageContext.request.contextPath}/accountController/delete',
													{
														id : id
													},
													function(result) {
														if (result.success) {
															parent.$.messager
																	.alert(
																			'提示',
																			result.msg,
																			'info');
															dataGrid2
																	.datagrid('reload');
														}
														parent.$.messager
																.progress('close');
													}, 'JSON');
								} else {
									parent.$.messager.show({
										title : '提示',
										msg : '不可以删除自己！'
									});
								}
							}
						});
		dataGrid2.datagrid('unselectAll').datagrid('uncheckAll');
	}

	function addFun() {
		parent.$
				.modalDialog({
					title : '开户',
					width : 300,
					height : 130,
					href : '${pageContext.request.contextPath}/accountController/addPage?uid=${account.uid}',
					buttons : [ {
						text : '开户',
						handler : function() {
							parent.$.modalDialog.openner_dataGrid = dataGrid2;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
							var f = parent.$.modalDialog.handler.find('#form');
							f.submit();
						}
					} ]
				});
	}

	function acmngFun() {
		var rows = dataGrid2.datagrid('getSelections');
		var acid = rows[0].id;
		var t = rows[0].type;
		var tstr = rows[0].typeStr;
		var cstr = rows[0].currencyStr;
		var amount = rows[0].amount;
		var l = '';
		if (t == 1) {
			l = '${pageContext.request.contextPath}/accountController/hqmanager?id='
					+ acid;
		} else if (t == 2) {
			l = '${pageContext.request.contextPath}/accountController/dqmanager?id='
					+ acid;
		} else {
			l = '${pageContext.request.contextPath}/accountController/dhmanager?id='
					+ acid;
		}
		l += '&typeStr='+tstr+'&currencyStr='+cstr+'&amount='+amount;
		/* 			addTab({
		 url : l,
		 title : '账户管理',
		 iconCls : 'money_dollar'
		 });
		 parent.$.modalDialog("close"); 
		 } */
		parent.$.modalDialog({
			title : '储蓄账户管理',
			width : 800,
			height : 600,
			href : l,
			id : 'acmndialog'
		});
		 //$('#accountdialog').dialog('refresh');
	}
</script>
<div class="easyui-layout" data-options="fit : true,border : false">
	<div data-options="region:'center',border:false">
		<table id="dataGrid2"></table>
	</div>
</div>
<div id="toolbar" style="display: none;">
	         一卡通账号:${account.uname} 
	     <c:if test="${sessionScope.sessionInfo.loginType}!=5">
	     <a onclick="addFun();"
		href="javascript:void(0);" class="easyui-linkbutton"
		data-options="plain:true,iconCls:'pencil_add'">储蓄账户开户</a> 
		</c:if>
</div>

<div id="menu" class="easyui-menu" style="width: 120px; display: none;">
	<div onclick="acmngFun();" data-options="iconCls:'money_dollar'">账户操作</div>
	<c:if test="${sessionScope.sessionInfo.loginType}!=5">
	<div onclick="deleteFun();" data-options="iconCls:'pencil_delete'">销户</div>
	</c:if>
</div>
